From: Ian Campbell Date: Fri, 3 Dec 2010 09:36:47 +0000 (+0000) Subject: libxc: move foreign memory functions to xc_foreign_memory.c X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~11045 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22%22/%22http:/www.example.com/cgi/%22https:/%22%22?a=commitdiff_plain;h=fd81c3683ab201bef87a7e9f52e61be161993752;p=xen.git libxc: move foreign memory functions to xc_foreign_memory.c Now that this file exists it is a better home for these than xc_misc.c Signed-off-by: Ian Campbell Signed-off-by: Ian Jackson --- diff --git a/tools/libxc/xc_foreign_memory.c b/tools/libxc/xc_foreign_memory.c index 907c02bd7e..2c6d8d3952 100644 --- a/tools/libxc/xc_foreign_memory.c +++ b/tools/libxc/xc_foreign_memory.c @@ -20,6 +20,37 @@ #include "xc_private.h" +void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot, + const xen_pfn_t *arr, int num) +{ + void *res; + int i, *err; + + if (num < 0) { + errno = -EINVAL; + return NULL; + } + + err = malloc(num * sizeof(*err)); + if (!err) + return NULL; + + res = xc_map_foreign_bulk(xch, dom, prot, arr, err, num); + if (res) { + for (i = 0; i < num; i++) { + if (err[i]) { + errno = -err[i]; + munmap(res, num * PAGE_SIZE); + res = NULL; + break; + } + } + } + + free(err); + return res; +} + void *xc_map_foreign_range(xc_interface *xch, uint32_t dom, int size, int prot, unsigned long mfn) { @@ -49,6 +80,47 @@ void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot, dom, prot, arr, err, num); } +/* stub for all not yet converted OSes */ +void *xc_map_foreign_bulk_compat(xc_interface *xch, xc_osdep_handle h, + uint32_t dom, int prot, + const xen_pfn_t *arr, int *err, unsigned int num) +{ + xen_pfn_t *pfn; + unsigned int i; + void *ret; + + if ((int)num <= 0) { + errno = EINVAL; + return NULL; + } + + pfn = malloc(num * sizeof(*pfn)); + if (!pfn) { + errno = ENOMEM; + return NULL; + } + + memcpy(pfn, arr, num * sizeof(*arr)); + ret = xc_map_foreign_batch(xch, dom, prot, pfn, num); + + if (ret) { + for (i = 0; i < num; ++i) + switch (pfn[i] ^ arr[i]) { + case 0: + err[i] = 0; + break; + default: + err[i] = -EINVAL; + break; + } + } else + memset(err, 0, num * sizeof(*err)); + + free(pfn); + + return ret; +} + /* * Local variables: * mode: C diff --git a/tools/libxc/xc_misc.c b/tools/libxc/xc_misc.c index 23398f773b..47f97c55f2 100644 --- a/tools/libxc/xc_misc.c +++ b/tools/libxc/xc_misc.c @@ -512,78 +512,6 @@ int xc_hvm_set_mem_type( } -/* stub for all not yet converted OSes */ -void *xc_map_foreign_bulk_compat(xc_interface *xch, xc_osdep_handle h, - uint32_t dom, int prot, - const xen_pfn_t *arr, int *err, unsigned int num) -{ - xen_pfn_t *pfn; - unsigned int i; - void *ret; - - if ((int)num <= 0) { - errno = EINVAL; - return NULL; - } - - pfn = malloc(num * sizeof(*pfn)); - if (!pfn) { - errno = ENOMEM; - return NULL; - } - - memcpy(pfn, arr, num * sizeof(*arr)); - ret = xc_map_foreign_batch(xch, dom, prot, pfn, num); - - if (ret) { - for (i = 0; i < num; ++i) - switch (pfn[i] ^ arr[i]) { - case 0: - err[i] = 0; - break; - default: - err[i] = -EINVAL; - break; - } - } else - memset(err, 0, num * sizeof(*err)); - - free(pfn); - - return ret; -} - -void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot, - const xen_pfn_t *arr, int num) -{ - void *res; - int i, *err; - - if (num < 0) { - errno = -EINVAL; - return NULL; - } - - err = malloc(num * sizeof(*err)); - if (!err) - return NULL; - - res = xc_map_foreign_bulk(xch, dom, prot, arr, err, num); - if (res) { - for (i = 0; i < num; i++) { - if (err[i]) { - errno = -err[i]; - munmap(res, num * PAGE_SIZE); - res = NULL; - break; - } - } - } - - free(err); - return res; -} - /* * Local variables: * mode: C